// import json from 'rollup-plugin-json'
import { RollupOptions } from 'rollup'
// import typescript from "rollup-plugin-typescript";
import { eslint } from 'rollup-plugin-eslint'
// import sourceMaps from "rollup-plugin-sourcemaps";
import rollupTypescript from 'rollup-plugin-typescript2'
import babel from 'rollup-plugin-babel'
import { DEFAULT_EXTENSIONS } from '@babel/core'

const rollupConfig = {
  input: 'src/index.ts',
  output: [
    {
      file: 'lib/index.js',
      format: 'cjs'
    },
    {
      file: 'lib/index.esm.js',
      format: 'es'     
    }
  ],
  external: ['lodash'],
  plugins: [
    // 先进行eslint检查，保持无法进行下一步
    eslint({
      throwOnError: true, // lint 结果有错误将会抛出异常
      throwOnWarning: true,
      include: ['src/**/*.ts'],
      exclude: ['node_modules/**', 'lib/**', '*.js'],
    }),
    rollupTypescript(),
    babel({
      runtimeHelpers: true,
      // 只转换源代码，不运行外部依赖
      exclude: 'node_modules/**',
      // babel 默认不支持 ts 需要手动添加
      extensions: [
        ...DEFAULT_EXTENSIONS,
        '.ts',
      ],
    }),
  ]
};

export default rollupConfig